package main

import (
	"encoding/json"
	"fmt"
)

type Person struct {
	Name   string
	Age    int
	Gender int
	Hobby  string
}

func main() {

	person := Person{
		Name:   "Paul Gorge",
		Age:    33,
		Gender: 1,
		Hobby:  "Basketball",
	}

	result, err := json.Marshal(person)
	if err != nil {
		fmt.Printf("got err %v, while json encoding\n", err)
		return
	}

	jsonStr := string(result)

	fmt.Printf("The encoding result is %s\n", jsonStr)

	bytes := []byte(jsonStr)

	var person1 Person

	err1 := json.Unmarshal(bytes, &person1)
	if err1 != nil {
		fmt.Printf("got error while unarshal %v\n", err1)
		return
	}

	fmt.Printf("parsed result %#v\n", person1)

}
